package com.hk.employeemanagementsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hk.employeemanagementsystem.mapper.UserEntityMapper;
import com.hk.employeemanagementsystem.entity.UserEntity;
import com.hk.employeemanagementsystem.service.UserEntityService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author by 何坤
 * @Classname UserEntityServiceImpl
 * @Description TODO
 * @Date 2019/12/4 17:01
 */
@Service
public class UserEntityServiceImpl extends ServiceImpl<UserEntityMapper, UserEntity> implements UserEntityService {

    @Resource
    private UserEntityMapper userEntityMapper;

    @Override
    public UserEntity getMainInfo(String phone) {
        return userEntityMapper.selectOne(new QueryWrapper<UserEntity>().eq("user_phone", phone));
    }

    @Override
    public List<UserEntity> selectUserByKeyword(String keyword) {
        return userEntityMapper.selectUserByKeyword(keyword);
    }

    @Override
    public void updateUserEnableById(Integer userId, Boolean enable) {
        userEntityMapper.updateUserEnableById(userId, enable);
    }

    @Override
    public UserEntity getUserById(Integer userId) {
        return userEntityMapper.getUserById(userId);
    }

    @Override
    public int addRolesForUser(String phone, Integer[] rids) {
        userEntityMapper.deleteRoleByUserPhone(phone);
        if (rids.length == 0) {
            return 0;
        }
        return userEntityMapper.addRolesForUser(phone, rids);
    }
}
